home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / music / cthugha5.zip / CTHU5SRC.ZIP / MODES.C < prev    next >
C/C++ Source or Header  |  1994-08-19  |  10KB  |  540 lines

  1. //
  2. // Cthugha - Audio Seeded Image Processing
  3. //
  4. // Zaph, Digital Aasvogel Group, Torps Productions 1993-1994
  5. //
  6.  
  7.  
  8.  
  9. #include <stdio.h>
  10. #include <dos.h>
  11. #include <io.h>
  12. #include <fcntl.h>
  13. #include <stdlib.h>
  14. #include <math.h>
  15. #include <conio.h>
  16. #include <bios.h>
  17. #include <memory.h>
  18.  
  19. #include "cthugha.h"
  20. #include "charset.h"
  21. #include "zorilkey.h"
  22.  
  23. /* Defines for Soundblaster and Soundblaster Pro IO address */
  24.  
  25. void fill_buff(void);
  26. extern void display_up(void);
  27. extern void display_dn(void);
  28. void effect_0(void);
  29. void effect_1(void);
  30. void effect_2(void);
  31. void effect_3(void);
  32. extern void draw_text(int xpos, int ypos, int size, int colour, char *tbuf);
  33.  
  34.  
  35. void massage_audio(void)
  36. {
  37.     int temp,x;
  38.     int temp2;
  39.     int top=0;
  40.  
  41.     switch (massageStyle) {
  42.         case 0:
  43.         default:
  44.             break;
  45.         case 1:
  46.             temp=stereo[0][1];
  47.             temp2=stereo[0][0];
  48.             for (x=1; x<BUFF_WIDTH; x++) {
  49.                 if ((stereo[x][1]-temp)>10) {
  50.                     stereo[x][1]=temp+10;
  51.                 } else if ((stereo[x][1]-temp)<-10) {
  52.                     stereo[x][1]=temp-10;
  53.                 }
  54.                 if ((stereo[x][0]-temp2)>10) {
  55.                     stereo[x][0]=temp2+10;
  56.                 } else if ((stereo[x][0]-temp2)<-10) {
  57.                     stereo[x][0]=temp2-10;
  58.                 }
  59.                 temp=stereo[x][1];
  60.                 temp2=stereo[x][0];
  61.             }
  62.             break;
  63.         case 2:
  64.             temp=stereo[0][1];
  65.             temp2=stereo[0][0];
  66.             for (x=1; x<BUFF_WIDTH; x++) {
  67.                 if ((stereo[x][1]-temp)>3) {
  68.                     stereo[x][1]=temp+3;
  69.                 } else if ((stereo[x][1]-temp)<-3) {
  70.                     stereo[x][1]=temp-3;
  71.                 }
  72.                 if ((stereo[x][0]-temp2)>3) {
  73.                     stereo[x][0]=temp2+3;
  74.                 } else if ((stereo[x][0]-temp2)<-3) {
  75.                     stereo[x][0]=temp2-3;
  76.                 }
  77.                 temp2=stereo[x][0];
  78.                 temp=stereo[x][1];
  79.             }
  80.             break;
  81.     }
  82.  
  83. }
  84.  
  85. static void do_vwave(int ystart,int yend,int x,unsigned int val)
  86. {
  87.     int y,ys,ye;
  88.  
  89.     ystart=min(max(ystart,0),BUFF_HEIGHT-1);
  90.     yend=min(max(yend,0),BUFF_HEIGHT-1);
  91.  
  92.     x=min(max(x,0),BUFF_WIDTH-1);
  93.  
  94.     if (ystart>yend) {
  95.         ye=ystart;
  96.         ys=yend;
  97.     } else {
  98.         ys=ystart;
  99.         ye=yend;
  100.     }
  101.  
  102.  
  103.     for (y=ys; y<=ye; y++)
  104.         buff[y][x]=val;
  105. }
  106.  
  107. static void do_hwave(int xstart,int xend,int y,unsigned int val)
  108. {
  109.     int x,xs,xe;
  110.  
  111.     xstart=min(max(xstart,0),BUFF_WIDTH-1);
  112.     xend=min(max(xend,0),BUFF_WIDTH-1);
  113.  
  114.     y=min(max(y,0),BUFF_HEIGHT-1);
  115.  
  116.     if (xstart>xend) {
  117.         xe=xstart;
  118.         xs=xend;
  119.     } else {
  120.         xs=xstart;
  121.         xe=xend;
  122.     }
  123.  
  124.  
  125.     for (x=xs; x<=xe; x++)
  126.         buff[y][x]=val;
  127. //    memset(&(buff[y][xs]),val,(xe-xs+1));
  128. }
  129.  
  130.  
  131. static void wave_buff0(void)
  132. {
  133.     int temp,x;
  134.  
  135.     for (x=0; x<BUFF_WIDTH; x++) {
  136.         temp=stereo[x][0];
  137.         buff[BUFF_BOTTOM-(temp>>2)-20][(x)>>1]=table[curtable][temp];
  138.         temp=stereo[x][1];
  139.         buff[BUFF_BOTTOM-(temp>>2)-20][(x+BUFF_WIDTH)>>1]=table[curtable][temp];
  140.     }
  141.  
  142. }
  143.  
  144. static void wave_buff1(void)
  145. {
  146.     int temp,x;
  147.  
  148.  
  149.     for (x=0; x<BUFF_WIDTH; x++) {
  150.         temp=stereo[x][0];
  151.         buff[BUFF_BOTTOM-(temp>>1)-20][(x)>>1]=table[curtable][temp];
  152.         temp=stereo[x][1];
  153.         buff[BUFF_BOTTOM-(temp>>1)-20][(x+BUFF_WIDTH)>>1]=table[curtable][temp];
  154.     }
  155.  
  156. }
  157.  
  158. static void wave_buff2(void)
  159. {
  160.     int temp,x;
  161.  
  162.     for (x=0; x<BUFF_BOTTOM; x++) {
  163.         temp=stereo[x][0];
  164.         buff[x][160-(temp>>2)]=table[curtable][temp];
  165.         temp=stereo[x][1];
  166.         buff[x][160+(temp>>2)]=table[curtable][temp];
  167.     }
  168.  
  169. }
  170.  
  171. static void wave_buff3(void)
  172. {
  173.     int temp,x,i;
  174.  
  175.  
  176.     for (x=0; x<BUFF_WIDTH; x++) {
  177.         temp=abs(128-stereo[x][0])>>1;
  178.         for (i=0; i<temp; i++)
  179.             buff[BUFF_BOTTOM-i][(x)>>1]=table[curtable][i];
  180.  
  181.         temp=abs(128-stereo[x][1])>>1;
  182.         for (i=0; i<temp; i++)
  183.             buff[BUFF_BOTTOM-i][(x+BUFF_WIDTH)>>1]=table[curtable][i];
  184.     }
  185.  
  186. }
  187.  
  188. static void wave_buff4(void)
  189. {
  190.     int temp,x,i;
  191.  
  192.  
  193.     for (x=0; x<BUFF_WIDTH; x++) {
  194.         temp=abs(128-stereo[x][0]);
  195.         for (i=0; i<temp; i++)
  196.             buff[BUFF_BOTTOM-i][x>>1]=table[curtable][temp];
  197.     }
  198.  
  199.     for (x=0; x<BUFF_WIDTH; x++) {
  200.         temp=abs(128-stereo[x][1]);
  201.         for (i=0; i<temp; i++)
  202.             buff[BUFF_BOTTOM-i][(x+BUFF_WIDTH)>>1]=table[curtable][temp];
  203.     }
  204.  
  205. }
  206.  
  207. static void wave_buff5(void)
  208. {
  209.     int temp,x,y;
  210.     int last=128;
  211.  
  212.  
  213.     for (y=0; y<2; y++)
  214.         for (x=0; x<BUFF_WIDTH; x++) {
  215.             temp=stereo[x][y];
  216.             do_vwave(BUFF_BOTTOM-(temp>>2),BUFF_BOTTOM-(last>>2),(y)?((x+BUFF_WIDTH)>>1):(x>>1),table[curtable][temp]);
  217.             last=temp;
  218.         }
  219.  
  220. }
  221.  
  222. static void wave_buff6(void)
  223. {
  224.     int temp,x,y;
  225.     int last=128;
  226.  
  227.  
  228.     for (y=0; y<2; y++)
  229.         for (x=0; x<BUFF_WIDTH; x++) {
  230.             temp=stereo[x][y];
  231.             do_vwave(BUFF_BOTTOM-(temp>>1),BUFF_BOTTOM-(last>>1),(y)?((x+BUFF_WIDTH)>>1):(x>>1),table[curtable][temp]);
  232.             last=temp;
  233.         }
  234.  
  235. }
  236.  
  237. static void wave_buff7(void)
  238. {
  239.     int temp,x;
  240.  
  241.     for (x=0; x<BUFF_BOTTOM; x++) {
  242.         temp=stereo[x][0];
  243.         buff[x][160-(temp>>1)]=table[curtable][temp];
  244.         temp=stereo[x][1];
  245.         buff[x][160+(temp>>1)]=table[curtable][temp];
  246.     }
  247.  
  248. }
  249.  
  250. static void wave_buff8(void)
  251. {
  252.     int temp,x,y;
  253.     int last=0;
  254.  
  255.  
  256.     for (y=0; y<2; y++)
  257.         for (x=0; x<BUFF_WIDTH; x++) {
  258.             temp=stereo[x][y];
  259.             temp=abs(128-temp);
  260.             do_vwave(BUFF_BOTTOM-(temp),BUFF_BOTTOM-(last),(y)?((x+BUFF_WIDTH)>>1):(x>>1),table[curtable][temp]);
  261.             last=temp;
  262.         }
  263.  
  264. }
  265.  
  266. static void wave_buff9(void)   // *******************************************
  267. {
  268.  
  269.     int temp,x,last1=128,last2=128;
  270.     static col=128;
  271.  
  272.     col=(col+1)%BUFF_WIDTH;
  273.  
  274.  
  275.     for (x=0; x<BUFF_BOTTOM; x++) {
  276.         temp=stereo[x][0];
  277.         do_hwave(col-(temp>>2),col-(last1>>2),x,table[curtable][temp]);
  278.         last1=temp;
  279.  
  280.         temp=stereo[x][1];
  281.         do_hwave(col+(temp>>2),col+(last2>>2),x,table[curtable][temp]);
  282.         last2=temp;
  283.     }
  284. }
  285.  
  286. static void wave_buff10(void)   // *******************************************
  287. {
  288.     int i;
  289.     static int row=0;
  290.  
  291.     row=(row+1)%(BUFF_BOTTOM-1);
  292.  
  293.     for (i=0; i<160; i++) {
  294.         buff[row+1][i]    =table[curtable][stereo[i][0]];
  295.         buff[row+1][i+160]=table[curtable][stereo[i][1]];
  296.         buff[row][i]      =table[curtable][stereo[i+160][0]];
  297.         buff[row][i+160]  =table[curtable][stereo[i+160][1]];
  298.     }
  299.  
  300. }
  301.  
  302. static void wave_buff11(void) // **************************************
  303. {
  304.     int temp,x,temp2;
  305.     
  306.     for (x=0; x<BUFF_WIDTH; x++) {
  307.         temp=stereo[x][0];
  308.         temp2=stereo[x][1];
  309.  
  310.         buff[(temp+200-28)%BUFF_BOTTOM][(temp2+32)%BUFF_WIDTH]=table[curtable][temp];
  311.     }
  312.  
  313. }
  314.  
  315. static void wave_buff12(void)
  316. {
  317.     int temp,x,last1=128,last2=128;
  318.  
  319.     for (x=0; x<BUFF_BOTTOM; x++) {
  320.         temp=stereo[x][0];
  321.         do_hwave(BUFF_WIDTH/2-(temp>>2),BUFF_WIDTH/2-(last1>>2),x,table[curtable][temp]);
  322.         last1=temp;
  323.  
  324.         temp=stereo[x][1];
  325.         do_hwave(BUFF_WIDTH/2+(temp>>2),BUFF_WIDTH/2+(last2>>2),x,table[curtable][temp]);
  326.         last2=temp;
  327.     }
  328.  
  329. }
  330.  
  331. static void wave_buff13(void)
  332. {
  333.     int temp,x,last1=128,last2=128;
  334.  
  335.     for (x=0; x<BUFF_BOTTOM; x++) {
  336.         temp=stereo[x][0];
  337.         do_hwave(BUFF_WIDTH/2-(temp>>1),BUFF_WIDTH/2-(last1>>1),x,table[curtable][temp]);
  338.         last1=temp;
  339.  
  340.         temp=stereo[x][1];
  341.         do_hwave(BUFF_WIDTH/2+(temp>>1),BUFF_WIDTH/2+(last2>>1),x,table[curtable][temp]);
  342.         last2=temp;
  343.     }
  344.  
  345. }
  346.  
  347. static void wave_buff14(void)
  348. {
  349.     int temp,x,last=128;
  350.  
  351.     for (x=0; x<BUFF_BOTTOM; x++) {
  352.         temp=stereo[x][0];
  353.         do_hwave(160-(temp>>2),160-(last>>2),x,table[curtable][temp]);
  354.         last=temp;
  355.     }
  356.  
  357.     for (x=0; x<BUFF_BOTTOM; x++) {
  358.         temp=stereo[x][1];
  359.         do_hwave(120+(temp>>2),120+(last>>2),x,table[curtable][temp]);
  360.         last=temp;
  361.     }
  362.  
  363. }
  364.  
  365. static void wave_buff15(void)
  366. {
  367.     int temp=100,x,last=100;
  368.  
  369.     for (x=0; x<BUFF_BOTTOM; x++) {
  370.  
  371.         temp=((stereo[x][0]-127)/16)+last;
  372.  
  373.         if (temp>=BUFF_WIDTH)
  374.             temp=BUFF_WIDTH-1;
  375.         if (temp<0)
  376.             last=0;
  377.  
  378.         temp=temp%BUFF_WIDTH;
  379. //        do_hwave(temp,last,x,table[curtable][temp]);
  380.         do_hwave(temp,last,x,255);
  381.         last=temp;
  382.     }
  383.  
  384.     last=200; temp=200;
  385.     for (x=0; x<BUFF_BOTTOM; x++) {
  386.  
  387.         temp=((stereo[x][1]-127)/16)+last;
  388.  
  389.         if (temp>=BUFF_WIDTH)
  390.             temp=BUFF_WIDTH-1;
  391.         if (temp<0)
  392.             last=0;
  393.  
  394.         temp=temp%BUFF_WIDTH;
  395. //        do_hwave(temp,last,x,table[curtable][temp]);
  396.         do_hwave(temp,last,x,255);
  397.         last=temp;
  398.  
  399.     }
  400. }
  401.  
  402. static void wave_buff16(void)
  403. {
  404.     int temp=100,x,last=100;
  405.  
  406.  
  407.     for (x=0; x<BUFF_BOTTOM; x++) {
  408.         temp=((stereo[x][0]-127)/32)+last;
  409.         if (temp>=BUFF_WIDTH)
  410.             temp=BUFF_WIDTH-1;
  411.         if (temp<0)
  412.             last=0;
  413.  
  414.         temp=temp%BUFF_WIDTH;
  415. //        do_hwave(temp,last,x,table[curtable][temp]);
  416.         do_hwave(temp,last,x,255);
  417.         last=temp;
  418.  
  419.     }
  420.  
  421.     last=200; temp=200;
  422.     for (x=0; x<BUFF_BOTTOM; x++) {
  423.         temp=((stereo[x][1]-127)/32)+last;
  424.  
  425.         if (temp>=BUFF_WIDTH)
  426.             temp=BUFF_WIDTH-1;
  427.         if (temp<0)
  428.             last=0;
  429.  
  430. //        temp=temp%BUFF_WIDTH;
  431. //        do_hwave(temp,last,x,table[curtable][temp]);
  432.         do_hwave(temp,last,x,255);
  433.         last=temp;
  434.  
  435.     }
  436. }
  437.  
  438.  
  439. static void wave_buff17(void)
  440. {
  441.     int temp=160,x,last=160;
  442.  
  443.     for (x=0; x<BUFF_BOTTOM; x++) {
  444.         temp=stereo[x][0];
  445.         buff[x][160-(temp>>2)]=table[curtable][temp];
  446.         temp=stereo[x][1];
  447.         buff[x][160+(temp>>2)]=table[curtable][temp];
  448.     }
  449.  
  450. }
  451.  
  452.  
  453. int usewave=0;
  454. void next_wave(void)
  455. {
  456.     usewave=(usewave+1)%NUMWAVES;
  457. }
  458.  
  459. void change_wave(int wavenum)
  460. {
  461.     usewave=wavenum%NUMWAVES;
  462. }
  463.  
  464. void wave(void) {
  465.     switch (usewave) {
  466.         case 0:
  467.         default:
  468.             wave_buff0();
  469.             break;
  470.         case 1:
  471.             wave_buff1();
  472.             break;
  473.         case 2:
  474.             wave_buff2();
  475.             break;
  476.         case 3:
  477.             wave_buff3();
  478.             break;
  479.         case 4:
  480.             wave_buff4();
  481.             break;
  482.         case 5:
  483.             wave_buff5();
  484.             break;
  485.         case 6:
  486.             wave_buff6();
  487.             break;
  488.         case 7:
  489.             wave_buff7();
  490.             break;
  491.         case 8:
  492.             wave_buff8();
  493.             break;
  494.         case 9:
  495.             wave_buff9();
  496.             break;
  497.         case 10:
  498.             wave_buff10();
  499.             break;
  500.         case 11:
  501.             wave_buff11();
  502.             break;
  503.         case 12:
  504.             wave_buff12();
  505.             break;
  506.         case 13:
  507.             wave_buff13();
  508.             break;
  509.         case 14:
  510.             wave_buff14();
  511.             break;
  512.         case 15:
  513.             wave_buff15();
  514.             break;
  515.         case 16:
  516.             wave_buff16();
  517.             break;
  518.         case 17:
  519.             wave_buff17();
  520.             break;
  521.         case 18:
  522.             pete_0();
  523.             break;
  524.         case 19:
  525.             pete_1();
  526.             break;
  527.         case 20:
  528.             pete_2();
  529.             break;
  530.         case 21:
  531.             moles_fract();
  532.             break;
  533.         case 22:
  534.             moles_fract2();
  535.             break;
  536.     }
  537. }
  538.  
  539.  
  540.